package utils;

import java.text.Collator;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;

import beans.ComboBean;
import beans.TimeoutBean;
import beans.WarningInfoBean;

/**
 * Created by Administrator on 2018/8/8.
 */

public class ComboSetSortUtils {

    /**
     * 物品
     * @param list
     * @param flag
     */
    public static void sortComboSetGoods(List<ComboBean.DataBean> list, boolean flag){

        if (flag) {
            Collections.sort(list, new Comparator<ComboBean.DataBean>() {
                @Override
                public int compare(ComboBean.DataBean o1, ComboBean.DataBean o2) {
                    Collator ca = Collator.getInstance(Locale.CHINA);
                    if (ca.compare(o2.getPackageName(), o1.getPackageName()) < 0) {
                        return 1;
                    } else if (ca.compare(o2.getPackageName(), o1.getPackageName()) == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        } else {
            Collections.sort(list, new Comparator<ComboBean.DataBean>() {
                @Override
                public int compare(ComboBean.DataBean o1, ComboBean.DataBean o2) {
                    Collator ca = Collator.getInstance(Locale.CHINA);
                    if (ca.compare(o2.getPackageName(), o1.getPackageName()) > 0) {
                        return 1;
                    } else if (ca.compare(o2.getPackageName(), o1.getPackageName()) == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        }
    }

    /**
     * 供应商
     * @param list
     * @param flag
     */
    public static void sortComboSetCategory(List<ComboBean.DataBean> list,boolean flag){

        if (flag) {
            Collections.sort(list, new Comparator<ComboBean.DataBean>() {
                @Override
                public int compare(ComboBean.DataBean o1, ComboBean.DataBean o2) {
                    Collator ca = Collator.getInstance(Locale.CHINA);
                    if (o2.getGoodsCount() - o1.getGoodsCount() < 0) {
                        return 1;
                    } else if (o2.getGoodsCount() - o1.getGoodsCount() == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        } else {
            Collections.sort(list, new Comparator<ComboBean.DataBean>() {
                @Override
                public int compare(ComboBean.DataBean o1, ComboBean.DataBean o2) {
                    Collator ca = Collator.getInstance(Locale.CHINA);
                    if (o2.getGoodsCount() - o1.getGoodsCount() > 0) {
                        return 1;
                    } else if (o2.getGoodsCount() - o1.getGoodsCount() == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        }
    }
    /**
     * 规格
     * @param list
     * @param flag
     */
    public static void sortComboSetDate(List<ComboBean.DataBean> list, boolean flag){

        if (flag) {
            Collections.sort(list, new Comparator<ComboBean.DataBean>() {
                @Override
                public int compare(ComboBean.DataBean o1, ComboBean.DataBean o2) {
                    long time1 = Long.parseLong(TimeUtil.dateToStamp(o1.getSubTime()));
                    long time2 = Long.parseLong(TimeUtil.dateToStamp(o2.getSubTime()));
                    if (time2 - time1 < 0) {
                        return 1;
                    } else if (time2 - time1 == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        } else {
            Collections.sort(list, new Comparator<ComboBean.DataBean>() {
                @Override
                public int compare(ComboBean.DataBean o1, ComboBean.DataBean o2) {
                    long time1 = Long.parseLong(TimeUtil.dateToStamp(o1.getSubTime()));
                    long time2 = Long.parseLong(TimeUtil.dateToStamp(o2.getSubTime()));
                    if (time2 - time1 > 0) {
                        return 1;
                    } else if (time2 - time1 == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        }
    }
}
